package com.example.controller;

import com.example.entity.*;
import com.example.service.GoodsService;
import com.example.service.HistoryService;
import com.example.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/history")
public class HistoryController {
    @Autowired
    private HistoryService historyService;
    @Autowired
    private GoodsService goodsService;
    @RequestMapping("/list")
    public String list(HttpSession session, Model model){
        User user = (User) session.getAttribute("user");
        System.out.println(user);
        List<History> histories=historyService.FindHistoryByUid(user.getUid());
        System.out.println(histories);
        model.addAttribute("histories", histories);
        return "student/history";
    }

    @RequestMapping("/remove")
    public String remove(@RequestParam int hid, HttpSession session) {
        User user = (User) session.getAttribute("user");
        if(user == null) {
            return "redirect:/login";
        }

        historyService.remove(hid);
        return "redirect:/cart/list";
    }
}
